@extends('admin.public.header')
@section('title','编辑退货地址')

@section('listcontent')
    <div class="layui-tab-content">
        <form class="layui-form">
            <div class="layui-form layuimini-form">
                <input type="hidden" name="id" value="{{ $info->id ?? '' }}">
                <div class="layui-form-item">
                    <label class="layui-form-label required">收件人姓名</label> 
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" lay-reqtext="收件人姓名不能为空" placeholder="请输入收件人姓名" value="{{ $info->name ?? '' }}" class="layui-input"> 
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">收件人电话</label> 
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="mobile" placeholder="请输入收件人电话" value="{{ $info->mobile ?? '' }}" class="layui-input"> 
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">收件人地址</label> 
                    <div class="layui-input-block">
                        <input type="text" name="address" lay-verify="required" lay-reqtext="收件人地址不能为空" placeholder="请输入收件人地址" value="{{ $info->address ?? '' }}" class="layui-input"> 
                    </div>
                </div>
            </div>
            <div class="hr-line"></div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" id="saveBtn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
   
@endsection

@section('listscript')
    <script type="text/javascript">
        layui.use(['layer','form','tree','util'], function () {
            var layer = layui.layer, form = layui.form,
            $=layui.jquery ,tree = layui.tree ,
            util = layui.util;
            //自定义验证规则
            form.verify({
                mobile:function (value) {
                    if(value<=0||value.length <= 0){
                        return '手机号码不能为空，请确认输入！';
                    }else if(ValidatePhone(value) == false) {
                        return '手机号码格式错误';
                    }
                }
            });
            form.on('submit(saveBtn)', function(data){
                var loading = layer.msg('加载中..', {icon: 16,shade: 0.3,time: false});
                $.ajax({
                    url:'/admin/refund_address/edit',
                    type:'post',
                    data:data.field,
                    dataType:"JSON",
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    success:function(res){
                        layer.close(loading);  //返回数据关闭loading
                        if(res.code == 0){
                            layer.msg(res.message,{icon: 1},function(){
                                setTimeout('parent.location.reload()',500);
                            });
                            
                        }
                        else{
                            layer.msg(res.message,{icon: 2});
                        }
                    },
                    error:function(e){
                        layer.msg("提交失败",{icon: 2});
                    },
                    
                });
                return false;
            });

            //电话验证
            function ValidatePhone(val){
                var isPhone = /^1[3456789]\d{9}$/;//手机号码
                var isMob= /^0?1[0-9][0-9]\d{8}$/;// 座机格式
                if(isMob.test(val)||isPhone.test(val)){
                    return true;
                }else{
                    return false;
                }
            }
            

        });
    </script>
@endsection

